<!DOCTYPE html>
<html>
  <body>
    <script src="../../resources/js-test.js"></script>
    <div id="rootDiv">
      <div id="div1">A</div><div id="div2">B</div><div id="div3">C1<div id="div4">D</div><div id="div5">E</div>C2</div><div id="div6">F</div><div id="div6">G</div>
      <div id="description">Test various cases of Range.insertNode with nodes in the same container as the Range.</div>
    </div>
    <script>
      var range = document.createRange();

      var containerElement = document.getElementById("rootDiv");
      var insertedElement = document.getElementById("div1");

      range.setStart(containerElement, 3);
      range.setEnd(containerElement, 3);
      range.insertNode(insertedElement);

      shouldBe('range.toString()', '"A"');

      range.setStart(containerElement, 3);
      range.setEnd(containerElement, 3);
      range.insertNode(insertedElement);

      shouldBe('range.toString()', '"A"');

      insertedElement = document.getElementById("div3");

      range.setStart(containerElement, 5);
      range.setEnd(containerElement, 5);
      range.insertNode(insertedElement);

      shouldBe('range.toString()', '"C1DEC2"');

      range.setStart(containerElement, 5);
      range.setEnd(containerElement, 5);
      range.insertNode(insertedElement);

      shouldBe('range.toString()', '"C1DEC2"');

      insertedElement = document.getElementById("div6");

      range.setStart(containerElement, 1);
      range.setEnd(containerElement, 1);
      range.insertNode(insertedElement);

      shouldBe('range.toString()', '"F"');

      insertedElement = document.getElementById("div3");

      range.setStart(containerElement, 4);
      range.setEnd(containerElement, 4);
      range.insertNode(insertedElement);

      shouldBe('range.toString()', '"C1DEC2"');

      var documentFragment = range.extractContents();
      shouldBe('range.startContainer', 'containerElement');
      shouldBe('range.startOffset', '4');
      shouldBe('range.endContainer', 'containerElement');
      shouldBe('range.endOffset', '4');

      range.insertNode(documentFragment);
      shouldBe('range.toString()', '"C1DEC2"');
    </script>
  </body>
</html>